/*************************************************************************
	> File Name: 5-2.c
	> Author: Angel Criss
	> Mail: abbytsing@gmail.com 
	> Created Time: Thu Jul 24 14:14:02 2014
 ************************************************************************/
// with O_APPEND, the lseek will have no effect, because this is a  atomic operation

#include "ch-5.h"

int main(int argc,char *argv[])
{
    system("echo start > file");

    int fd;

    if((fd=open("file",O_RDWR|O_APPEND))==-1)
        err("open");
    lseek(fd,0,SEEK_SET);

    if(write(fd,"-end",4)==-1)
        err("write");

    printf("please view the \"file\"\n");
    sleep(10);
    remove("file");

    exit(0);
}
